var PATH_PREFIX2 ="";

function setPathPrefix2(path){
	PATH_PREFIX2 =  path;
}
$(function() {
	// 给select2组件加载样式
	WASP_WIDGET.initializeSelectStyle();
	// 注册清空事件
    WASP_WIDGET.registerResetClearEvent();
    
    WASP_WIDGET.triggerDateStyleWithYMD($("#cashBeginDate"));
    WASP_WIDGET.triggerDateStyleWithYMD($("#cashEndDate"));
    //初始化产品下拉框
    WASP_WIDGET.triggerPrdInfoSelect("prjCode");
});

var $tradeCashList = $('#tradeCashList');

$(function() {
	$tradeCashList.jqGrid({   
		url:PATH_PREFIX2+'tradeCashList.do',    
		//caption:'交易头寸列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',  
		datatype: "json",
		postData:{
			'sp[cashBeginDate]' : $("#cashBeginDate").val().replace(/-/g,""),
			'sp[cashEndDate]' : $("#cashEndDate").val().replace(/-/g,""),
			'sp[prjCode]' : $("#tradeCash #prjCode").val(),
			'sp[assetUnitId]' : $("#assetUnitId").val()
		},  
		colNames:["主键","产品代码","产品名称","资产单元","头寸明细","入款","出款","余额","头寸日期","备注"/*,"操作"*/],        
		colModel:[  { name: 'cashId', index: 'cashId', hidden: true, key: true, resizable: true, sortable: false },       
					{ name: 'prjCode', index: 'prjCode', hidden: true,resizable: true, sortable: false },
		            { name: 'prjName', index: 'prjName', resizable: true, sortable: false },
		            { name: 'assetUnitId', index: 'assetUnitId', hidden: false, resizable: true, sortable: false ,
						formatter:function(cellvalue, options, rowObject){
			        		if(cellvalue =="01"){
			        			return "场外";
			        		}else if(cellvalue =="02"){
			        			return "场内场外";
			        		}else{
			        			return cellvalue;
			        		}
			        	}
		            },
		            { name: 'cashDetail', index: 'cashDetail', width:400, resizable: true, sortable: false },
		            { name: 'paymentIn', index: 'paymentIn', resizable: true, sortable: false },
		            { name: 'paymentOut', index: 'paymentOut', resizable: true, sortable: false },
		            { name: 'balance', index: 'balance', resizable: true, sortable: false },
		            { name: 'cashDate', index: 'cashDate', resizable: true, sortable: false },
		            { name: 'remarks', index: 'remarks', width:400, resizable: true, sortable: false }/*,
		            { name: 'option', index: 'option', resizable: true, sortable: false }*/
				  ],
		rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: $(window).height()-285,
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		pager: "#tradeCashListPage",						
		gridComplete: function(){
			
		}
	});
	$tradeCashList.navGrid('#tradeCashListage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$tradeCashList.jqGrid('setFrozenColumns');
	jqGridResize($tradeCashList);
	$(".ui-jqgrid .ui-jqgrid-htable").css("width",$(".ui-jqgrid").width()-1);
	$(".ui-jqgrid .ui-jqgrid-btable").css("width",$(".ui-jqgrid").width()-1);
});

/**
 * 查询按钮
 * 根据条件查询数据
 * @param flag
 */
function queryByCondtion2(flag){
    var postData = $tradeCashList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
    	'sp[cashBeginDate]' : $("#cashBeginDate").val().replace(/-/g,""),
		'sp[cashEndDate]' : $("#cashEndDate").val().replace(/-/g,""),
		'sp[prjCode]' : $("#tradeCash #prjCode").val(),
		'sp[assetUnitId]' : $("#assetUnitId").val()
	});
    if (flag) {
    	$tradeCashList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid",[{page:1}]);//重新载入Grid表格
    } else {
    	$tradeCashList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid");//重新载入Grid表格
    }
}